package com.shop.feignClient.fallbackFactory;

import com.shop.feignClient.DiscountClient;
import com.shop.po.Discount;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author 'banxia'
 * @version 1.0
 * @description TODO
 * @date 2023/2/26 19:33
 */
@Component
@Slf4j
public class DiscountClientFallback implements FallbackFactory<DiscountClient> {
    @Override
    public DiscountClient create(Throwable throwable) {
        return new DiscountClient() {
            @Override
            public List<Discount> getDiscountBatch(List<Long> discountIds) {
                log.error("获取优惠券集合被熔断");
                log.error("异常信息:{}",throwable.getMessage());
                return null;
            }

            @Override
            public boolean changDiscountCount(Long discountId, Long count) {
                log.error("修改优惠券被熔断");
                log.error("异常信息:{}",throwable.getMessage());
                return false;
            }

            @Override
            public Discount getDiscountById(Long discountId) {
                log.error("获取优惠券信息被熔断");
                log.error("异常信息:{}",throwable.getMessage());
                return null;
            }
        };
    }
}
